package com.dpwgc.demo.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * 静态资源文件夹访问配置
 */
@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {

    @Value("${file.outside.prefix}")
    private String prefix;

    @Value("${spring.web.resources.static-locations}")
    private String locations;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String[] array = locations.split(",");
        ResourceHandlerRegistration resourceHandlerRegistration = registry.addResourceHandler(prefix+"/**");

        for (String s : array) {
            resourceHandlerRegistration.addResourceLocations(s);
        }
    }
}
